package org.example.web;

import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.dto.OrderPlacedEvent;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.http.HttpStatus;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class MessageController {
    @Resource
    KafkaTemplate kafkaTemplate;      //发消息
    @Resource
    ApplicationEventPublisher applicationEventPublisher;
    @PostMapping("/api/message")
    @ResponseStatus(HttpStatus.CREATED)
    public void sendMessage(String key,String message){
        kafkaTemplate.send("notTopic",key, new OrderPlacedEvent(key,message));
        applicationEventPublisher.publishEvent("消息发送");
      //  new Thread(()->mock()).start();
      //  CompletableFuture.runAsync(()->mock());
        log.info("提醒完成");
    }

}
